﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace OgilvyOne.UKNow.Configuration
{
    public class SiteConfig
    {
        private static readonly string C_NODE_NAME = "SiteConfig";
        private static readonly XmlDocument SiteConfigDocument = GetSiteConfigDocument();

        private static XmlDocument GetSiteConfigDocument()
        {
            try
            {
                string baseDir = AppDomain.CurrentDomain.BaseDirectory;
                string path = Path.Combine(baseDir, "ConfigFiles\\Site.config");
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                return doc;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Error occurred in SiteConfig.GetSiteConfigDocument. Message: {0}", ex.Message));
            }
        }

        public static string PressDownloadEmail = RetrieveNodeText(string.Format("/{0}/{1}", C_NODE_NAME, "PressDownloadEmail"));

        private static string RetrieveNodeText(string nodePath)
        {
            XmlNode node = SiteConfigDocument.SelectSingleNode(nodePath);
            if (node == null) return null;
            return node.InnerText;
        }

        public class Event
        {
            private const string C_NODE_NAME = "Event";

            public static readonly string CnEmptyShowDate = RetrieveNodeText(string.Format("/{0}/{1}/{2}", SiteConfig.C_NODE_NAME, C_NODE_NAME, "CNEmptyShowDate"));
            public static readonly string EnEmptyShowDate = RetrieveNodeText(string.Format("/{0}/{1}/{2}", SiteConfig.C_NODE_NAME, C_NODE_NAME, "ENEmptyShowDate"));
        }

        public class Search
        {
            private const string C_NODE_NAME = "Search";

            public static readonly string EnIndexPath = 
                RetrieveNodeText(string.Format("/{0}/{1}/{2}", SiteConfig.C_NODE_NAME, C_NODE_NAME, "EnIndexPath"));
            public static readonly string CnIndexPath =
                RetrieveNodeText(string.Format("/{0}/{1}/{2}", SiteConfig.C_NODE_NAME, C_NODE_NAME, "CnIndexPath"));
            public static readonly string EnFilePath =
                RetrieveNodeText(string.Format("/{0}/{1}/{2}", SiteConfig.C_NODE_NAME, C_NODE_NAME, "EnFilePath"));
            public static readonly string CnFilePath =
                RetrieveNodeText(string.Format("/{0}/{1}/{2}", SiteConfig.C_NODE_NAME, C_NODE_NAME, "CnFilePath"));
        }
    }
}
